package erp.education.server.beans.implementation.setup.school;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import erp.education.client.setup.school.StreamRequest;
import erp.education.server.beans.implementation.BaseService;
import erp.education.server.beans.implementation.ResultResponse;
import erp.education.server.beans.implementation.ServiceObject;
import erp.education.server.beans.interfaces.setup.school.StreamServiceI;
import erp.education.server.beans.interfaces.user.transaction.ServiceObjectI;
import erp.education.server.db.entites.setup.school.Schools;
import erp.education.server.db.entites.setup.school.Streams;
import erp.education.server.db.exceptions.DbExceptions;
@Component("streamService")
public class StreamService extends BaseService implements StreamServiceI {

	@Override
	public ServiceObjectI streamLoadService(StreamRequest streamRequest) throws DbExceptions {
		ServiceObjectI response=new ServiceObject();
		ResultResponse holder=new ResultResponse();
		 List result=new ArrayList();
		result.add(branchsDao.getBranchs());
		result.add(streamDao.getStreamGridList());
		holder.setResultList(result);
		response.setResponseObject(holder); 
		return response;
	}


	@Override
	public ServiceObjectI saveUpdateStreamDetails(StreamRequest streamRequest) throws DbExceptions {
		ServiceObjectI response=new ServiceObject();
		ResultResponse holder=new ResultResponse();
		 List result=new ArrayList();
		 Streams stream=null;
		  stream=streamDao.getStream(streamRequest.getBranchId(),streamRequest.getStreamName());
		 if(null==stream){
			 stream=new Streams();
			 stream.setBranchId(streamRequest.getBranchId());
		 }
		 stream.setStreamName(streamRequest.getStreamName());
		  streamDao.merge(stream);
		 
		holder.setResultList(result);
		response.setResponseObject(holder); 
		return response;
	}
}
